/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dandsoft.mavrep.manager;

import org.dandsoft.mavrep.dao.ArtifactDAO;
import org.dandsoft.mavrep.data.ArtifactJDO;
import org.dandsoft.mavrep.data.ArtifactName;
import org.dandsoft.mavrep.data.Checksum;
import org.dandsoft.mavrep.data.Resource;

/**
 *
 * @author fin
 */
public class ArtifactManagerImpl implements ArtifactManager {

    private static final String METADATA_RESOURCE_NAME = "maven-metadata.xml";
    private ArtifactDAO artifactDAO;

    public Resource getResource(ArtifactName artifactName, String resourceName) {
        return artifactDAO.get(artifactName).getResources().get(resourceName);
    }

    private boolean isMetadataResource(String resourceName) {
        return resourceName.startsWith(METADATA_RESOURCE_NAME);
    }

    @Override
    public void persistContent(ArtifactName artifactName, String resourceName, Resource content) {
        ArtifactJDO artifact = artifactDAO.get(artifactName);
        if (artifact == null) {
            artifact = new ArtifactJDO(artifactName);
        }
        artifact.getResources().put(resourceName, content);
        artifactDAO.persist(artifact);
    }

    @Override
    public boolean verifyChecksum(ArtifactName artifactName, String resourceName, Checksum checksum) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public ArtifactDAO getArtifactDAO() {
        return artifactDAO;
    }

    public void setArtifactDAO(ArtifactDAO artifactDAO) {
        this.artifactDAO = artifactDAO;
    }
}
